import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
    // beforeEnter: (to, from, next) => {
    //     // ...
    //     if(localStorage.getItem('token')=='张三'){
    //         next()
    //      }else{
    //          next('/login')
    //      }
    // }
  },
  {
    path: '/list/:name/:aa/:bb',
    name: 'list',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/list.vue')
  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  },
  {
    path: '/route/:id',
    name: 'route',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/route.vue')
  },
]

const router = new VueRouter({
  routes
})

// 全局守卫
// router.beforeEach((to,from,next)=>{
    // console.log(to);
    // console.log(from);
//    next()

//  如果用户名不是张三 不能访问其他的页面
// let token = localStorage.getItem('token')
// // if(token == '张三'){
// //     next()
// // }else{
// //     // next('/login')
// //     if(to.path == '/login'){
// //         next()
// //     }else{
// //         next('/login')
// //     }
// // }

// if(to.path !='/login' && token !='张三'){
//     next('/login')
// }else{
//     next()
// }
// })
export default router
